#include "global.h"

float dt = 0.005f; // 控制周期（单位：秒）

_st_Mpu mpu6050 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};        // MPU6050传感器数据
_st_Mpu_F mpu6050_F = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}; // 浮点数格式的MPU6050传感器数据

_st_Quaternion imuQuaternion = {1.0f, 0.0f, 0.0f, 0.0f}; // 四元数姿态
_st_EulerAngle imuEulerAngle = {0.0f, 0.0f, 0.0f};       // 角度姿态

_st_TxRemote txRemote = {0, 0, 0, 0, 0, 0, 0, 0}; // 发送数据结构体
_st_RxRemote rxRemote = {0, 0.0f, 0.0f, 0.0f};    // 接收数据结构体

_em_FlightState flightState = DISARMED; // 飞行状态 初始为安全锁定状态

// 外环PID数据结构体
_st_PidObject pidRoll = {
    .kp = 10.0f,
    .ki = 0.0f,
    .kd = 0.0f,

    .target = 0.0f,
    .measured = 0.0f,
    .error = 0.0f,
    .errorPre = 0.0f,
    .errorInteg = 0.0f,
    .errorIntegLimitLow = 0.0f,
    .errorIntegLimitHigh = 0.0f,
    .out = 0.0f,
    .outLimitLow = 0.0f,
    .outLimitHigh = 0.0f,
};
_st_PidObject pidPitch = {
    .kp = 10.0f,
    .ki = 0.0f,
    .kd = 0.0f,

    .target = 0.0f,
    .measured = 0.0f,
    .error = 0.0f,
    .errorPre = 0.0f,
    .errorInteg = 0.0f,
    .errorIntegLimitLow = 0.0f,
    .errorIntegLimitHigh = 0.0f,
    .out = 0.0f,
    .outLimitLow = 0.0f,
    .outLimitHigh = 0.0f,
};
_st_PidObject pidYaw = {
    .kp = 8.0f,
    .ki = 0.0f,
    .kd = 0.0f,

    .target = 0.0f,
    .measured = 0.0f,
    .error = 0.0f,
    .errorPre = 0.0f,
    .errorInteg = 0.0f,
    .errorIntegLimitLow = 0.0f,
    .errorIntegLimitHigh = 0.0f,
    .out = 0.0f,
    .outLimitLow = 0.0f,
    .outLimitHigh = 0.0f,
};

// 内环PID数据结构体
_st_PidObject pidRateX = {
    .kp = 1.5f,
    .ki = 0.0f,
    .kd = 0.2f,

    .target = 0.0f,
    .measured = 0.0f,
    .error = 0.0f,
    .errorPre = 0.0f,
    .errorInteg = 0.0f,
    .errorIntegLimitLow = 0.0f,
    .errorIntegLimitHigh = 0.0f,
    .out = 0.0f,
    .outLimitLow = 0.0f,
    .outLimitHigh = 0.0f,
};
_st_PidObject pidRateY = {
    .kp = 1.5f,
    .ki = 0.0f,
    .kd = 0.2f,

    .target = 0.0f,
    .measured = 0.0f,
    .error = 0.0f,
    .errorPre = 0.0f,
    .errorInteg = 0.0f,
    .errorIntegLimitLow = 0.0f,
    .errorIntegLimitHigh = 0.0f,
    .out = 0.0f,
    .outLimitLow = 0.0f,
    .outLimitHigh = 0.0f,
};
_st_PidObject pidRateZ = {
    .kp = 10.0f,
    .ki = 0.2f,
    .kd = 0.3f,

    .target = 0.0f,
    .measured = 0.0f,
    .error = 0.0f,
    .errorPre = 0.0f,
    .errorInteg = 0.0f,
    .errorIntegLimitLow = 0.0f,
    .errorIntegLimitHigh = 0.0f,
    .out = 0.0f,
    .outLimitLow = 0.0f,
    .outLimitHigh = 0.0f,
};
